/**
 * 创建人:冯斌    创建日期:2007-12-10
 */
package com.wsj.web.form;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;

/**
 * @author fengbin
 *
 */
public class BaseActionForm extends ActionForm{

    
    /**
     * 
     */
    private static final long serialVersionUID = -8008026955434574872L;

    protected ActionErrors errors;
    
    protected ActionMessages messages;
    
    //是否跳过验证
    protected boolean isPassValidate;

    public ActionErrors getErrors() {
        
        if(errors==null)
        {
            errors=new ActionErrors();
        }
        return errors;
    }

    public void setError(ActionErrors error) {
        this.errors = error;
    }

    public ActionMessages getMessages() {
        
        if(messages==null)
        {
            messages=new ActionMessages();
        }
        return messages;
    }

    public void setMessages(ActionMessages messages) {
        this.messages = messages;
    }
    
    
    /***
     * 检查传入的字符串不能为空
     * 不为空返回true
     * @return
     */
    public boolean checkInputStringIsOk(String input)
    { 
       boolean isok=true;
       if(input==null||input.trim().equals(""))
       {
           isok=false;
       }
       
       return isok;
    }

    public boolean isPassValidate() {
        return isPassValidate;
    }

    public void setPassValidate(boolean isPassValidate) {
        this.isPassValidate = isPassValidate;
    }

    public void setErrors(ActionErrors errors) {
        this.errors = errors;
    }
    
    
    /****
     * 是否跳过验证
     * 当action是update或者list的时候则跳过验证
     */
    
    public boolean checkAction(String action)
    {
        boolean ret=false;
        
        if(action!=null)
        {
            ret=action.contains("list");
            
            if(!ret)
            {
                ret=action.contains("toupdate");
            }
            
            
            if(!ret)
            {
                ret=action.contains("delete");
            }
        }
        
        return ret;
    }
    
    /***
     * 检查是否是update
     * 如果是更新页面,需要重新设置出错后跳转的页面
     */
    public boolean checkIsUpdateAction(String action)
    {
        boolean ret=false;
       if(action!=null)
       {
           ret=action.contentEquals("update");
       }
       
       return ret;
    }
    
}
